<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: 'App',
  components: {},
  async created() {
    // // 解决刷新页面 vuex数据丢失问题
    if (localStorage.getItem('store')) {
      await this.$store.replaceState(
        Object.assign({}, this.$store.state, JSON.parse(localStorage.getItem('store')))
      )
      console.log('app replace state')
    }
    window.addEventListener('beforeunload', () => {
      try {
        localStorage.setItem('store', JSON.stringify(this.$store.state))
      } catch (e) {
        localStorage.setItem('error', e)
      }
    })

    localStorage.removeItem('store')
  }
}
</script>

<style lang="less">
@import './assets/styles/reset.css';
@import './assets/styles/global.css';

* {
  margin: 0px;
  padding: 0px;
  font-family: 'Helvetica Neue', Helvetica, 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei',
    '微软雅黑', Arial, sans-serif;
}

#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

#app,
html,
body {
  width: 100%;
  height: 100%;
}
</style>
